package com.rds.eco.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.rds.common.annotation.Log;
import com.rds.common.api.eco.domain.RdaEco;
import com.rds.common.api.eco.domain.RdaEcoRel;
import com.rds.common.api.material.domain.MaterialBill;
import com.rds.common.core.controller.BaseController;
import com.rds.common.core.domain.AjaxResult;
import com.rds.common.core.domain.entity.Document;
import com.rds.common.core.page.TableDataInfo;
import com.rds.common.enums.BusinessType;
import com.rds.common.utils.poi.ExcelUtil;

import com.rds.eco.service.IRdaEcoService;
import com.rds.system.domain.Sharing;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2023-12-07
 */
@RestController
@RequestMapping("/pms/eco")
public class RdaEcoController extends BaseController
{
    @Autowired
    private IRdaEcoService rdaEcoService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:eco:list')")
    @GetMapping("/list")
    public TableDataInfo list(RdaEco rdaEco)
    {
        startPage();
        List<RdaEco> list = rdaEcoService.selectRdaEcoList(rdaEco);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:eco:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RdaEco rdaEco)
    {
        List<RdaEco> list = rdaEcoService.selectRdaEcoList(rdaEco);
        ExcelUtil<RdaEco> util = new ExcelUtil<RdaEco>(RdaEco.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:eco:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rdaEcoService.selectRdaEcoById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:eco:add')")
    @Log(title = "【新增eco】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RdaEco rdaEco)
    {
        return toAjax(rdaEcoService.insertRdaEco(rdaEco));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:eco:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RdaEco rdaEco)
    {
        return toAjax(rdaEcoService.updateRdaEco(rdaEco));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:eco:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rdaEcoService.deleteRdaEcoByIds(ids));
    }

    /**
     * 获取【受影响项目】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:eco:query')")
    @GetMapping(value = "/rel")
    public AjaxResult getEcoRel(Long id)
    {
        return success("获取受影响项目");
    }


    /**
     * eco基本信息新增文件
     */
    @PostMapping("/addFile")
    public AjaxResult addFile(@RequestBody Sharing rdaMemberlistUser){
        return toAjax(rdaEcoService.addFile(rdaMemberlistUser));
    }

    /**
     * eco引用现有物料
     */
    @Log(title = "插入现有零件作为子级", businessType = BusinessType.INSERT)
    @PostMapping("/InsertExistMaterial")
    public AjaxResult InsertExistMaterial(@RequestBody Sharing rdaPmsassignRel)
    {
        rdaEcoService.InsertExistMaterial(rdaPmsassignRel);
        return AjaxResult.success();
    }

    /**
     * eco添加物料
     */
    @Log(title = "插入现有零件作为子级", businessType = BusinessType.INSERT)
    @PostMapping("/InsertMaterial")
    public AjaxResult InsertMaterial(@RequestBody MaterialBill materialBill)
    {
        rdaEcoService.InsertMaterial(materialBill);
        return AjaxResult.success();
    }

    /**
     * eco引用现有文档
     */
    @Log(title = "插入现有零件作为子级", businessType = BusinessType.INSERT)
    @PostMapping("/InsertExistDoc")
    public AjaxResult InsertExistDoc(@RequestBody Sharing rdaPmsassignRel)
    {
        rdaEcoService.InsertExistDoc(rdaPmsassignRel);
        return AjaxResult.success();
    }

    /**
     * eco添加文档
     */
    @Log(title = "插入现有零件作为子级", businessType = BusinessType.INSERT)
    @PostMapping("/InsertDoc")
    public AjaxResult InsertDoc(@RequestBody Document document)
    {
        rdaEcoService.InsertDoc(document);
        return AjaxResult.success();
    }

    /**
     * 更加id查找關聯的物料
     */
    @PreAuthorize("@ss.hasPermi('system:eco:list')")
    @GetMapping("/selectRelsByEcoId")
    public TableDataInfo selectRelsByEcoId(Long id)
    {
        startPage();
        List<RdaEcoRel> list = rdaEcoService.selectRelsByEcoId(id);
        return getDataTable(list);
    }

    /**
     * 根据id移除ecorel表的数据
     */
    @PreAuthorize("@ss.hasPermi('system:eco:remove')")
    @Log(title = "【根据id移除ecorel表的数据】", businessType = BusinessType.DELETE)
    @DeleteMapping("/removeRelById/{ids}")
    public AjaxResult removeRelById(@PathVariable Long[] ids)
    {
        return toAjax(rdaEcoService.removeRelById(ids));
    }

    /**
     * 根据id跳转到物料中
     */
    @PreAuthorize("@ss.hasPermi('system:eco:remove')")
    @Log(title = "【根据id移除ecorel表的数据】", businessType = BusinessType.DELETE)
    @GetMapping(value = "/material/{id}")
    public JSONObject toMaterial(@PathVariable Long id)
    {
        rdaEcoService.toMaterial(id);
        return null;
    }

}
